function ajax(url,config){
    const {method = "get",headers={},data} = config;
    let body = "";
    if(config.method === "post"){
        if(data){
            body = JSON.stringify(data);
            headers["Content-Type"] = "application/json";
        }
    }
    return fetch(url,{
        method,
        headers,
        body
    }).then(value=>{
        return value.json();
    })
}
ajax.post = function(url,data){
    return ajax(url,{
        data,
        method:"post"
    })
}